const express = require("express");
const Personal = require("../middleware/personal");
const indexApp = express();
// 获取用户日记
indexApp.get("/", [Personal.getPersinal], (req, res) => {
  res.json(req.persinal);
});
// 获取全部日记
indexApp.get("/list", [Personal.getPersinalList], (req, res) => {
  res.json(req.persinalList);
});
// 获取日记详情
indexApp.get("/details", [Personal.getDetails], (req, res) => {
  res.json(req.details);
});
// 获取上一篇日记
indexApp.get("/prev", [Personal.getPrev], (req, res) => {
  res.json(req.prevPersinal);
});
// 获取删除日记
indexApp.post("/delete", [Personal.delete], (req, res) => {
  if (req.affectedRows > 0) {
    res.json({
      code: 1,
      msg: "删除成功",
    });
  } else {
    res.json({
      code: 0,
      msg: "删除失败",
    });
  }
});
// 日记添加
indexApp.post("/persinalAdd", [Personal.persinalAdd], (req, res) => {
  if (req.insertId) {
    res.json({
      code: 1,
      msg: "添加成功",
    });
  } else {
    res.json({
      code: 0,
      msg: "添加失败",
    });
  }
});
// 日记添加
indexApp.post("/persinalEdit", [Personal.persinalEdit], (req, res) => {
  if (req.insertId) {
    res.json({
      code: 1,
      msg: "添加成功",
    });
  } else {
    res.json({
      code: 0,
      msg: "添加失败",
    });
  }
});
module.exports = indexApp;
